#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
int main(int argc, char const *argv[])
{
    const char *filename = "./testFifo";
    int ret = access(filename, F_OK);
    if (ret != 0)
    {
        ret = mkfifo("./testFifo", 0644);
        if (ret == -1)
        {
            perror("mkfifo error:");
            _exit(-1);
        }
    }

    int readFd = open(filename, O_RDONLY);
    if (readFd == -1)
    {
        perror("open read error");
        _exit(-1);
    }
    char buf[128] = {0};
    int readBytes = 0;
    while (1)
    {
        readBytes = read(readFd, buf, sizeof(buf));
        if (readBytes < 0)
        {
            perror("read error:");
            _exit(-1);
        }
        else if (readBytes > 0)
        {
            printf("child readBytes = %d,\t buf = %s\n", readBytes, buf);
            memset(buf, 0, sizeof(buf));
        }
        else
        {
            break;
        }
    }
    close(readFd);
}